package com.xx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xx.entity.Products;
import com.xx.entity.ProductsDisplay;
import com.xx.mapper.ProductsMapper;
import com.xx.service.IProductsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xx.vo.ProductsDisplayVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ProductsServiceImpl implements IProductsService {
    @Autowired
    ProductsMapper productsMapper;


    @Override
    public List<ProductsDisplayVO> getListByProductId(List<Integer> productId) {
        return productsMapper.selectAllByProductIds(productId);
    }

    //通过ID查询
    @Override
    public ProductsDisplay queryById(Integer productId) {
        return productsMapper.queryById(productId);
    }

    //分页
    @Override
    public PageInfo<ProductsDisplay> queryByPage(Products products, Integer pageNum) {
        PageHelper.startPage(pageNum,5);
        List<ProductsDisplay> list =  productsMapper.queryAllByLimit(products);
        PageInfo<ProductsDisplay> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //新增
    @Override
    public int insert(Products products) {
        return productsMapper.insert(products);
    }

    //修改
    @Override
    public int update(Products products) {
        return productsMapper.update(products);
    }

    //删除
    @Override
    public int deleteById(Integer productId) {
        return productsMapper.deleteById(productId);
    }

    @Override
    public String selectImageUrl(Integer productId) {
        return productsMapper.selectImageUrl(productId);
    }
}
